package com.java.example.network

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
import java.lang.reflect.Type

/**
 * @author chenll
 * @date 2024/2/22
 * Des：
 */
class CustomConvertFactory private constructor(private val gson: Gson) : Converter.Factory() {
    override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *> {
        val adapter = gson.getAdapter(TypeToken.get(type))
        return CustomResponseBodyConverter(gson, adapter, annotations)
    }

    override fun requestBodyConverter(type: Type, parameterAnnotations: Array<Annotation>, methodAnnotations: Array<Annotation>, retrofit: Retrofit): Converter<*, RequestBody> {
        val adapter = gson.getAdapter(TypeToken.get(type))
        return CustomRequestBodyConverter(gson, adapter)
    }

    companion object {
         val SERVER_PUBLIC_KEY =
            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDS5ITReEgbkM62tbhisKRCxMpbfaOWME/Sokxyy26YjkgT3yMjSi/zYK+hU489pQLVF54XOArUjb+ljLZ75dT0weBBHDmOKm8j8V3QCll2P3LfvPE3BYh3PGrBxB9FpXS9+Ic3dkREiF34OtHDYfRVrseG4ml16vHGuA3fGOk1wwIDAQAB"
         val CLIENT_PRIVATE_KEY =
            "MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC+zFoZWGAdnX/258IRPFLr+Qre3qOc7V03YmuGQzlNquD/xd7aUZ7KzsllcVbBQGHh3kZsYCRwFvg2lfwZTjeD5ELh8NzZI97sCP+aDiI/IvEMWAF7zKMiPjKOMPxn4nno8U1yg1godcWXirQzpI/7Z2Hy9ZsLtZKRFAUWWk3UoJ2mDlWYxMt9XX6JHrH5I/5J9jHI6qKDOmlkc6Xe7OB/52N5BQnG5I2cCOZZO3ZPRT+lHqrjwsisctTaoqWJfCod78fR5pmPlAChjOXVHU3cwysA8sGUQeizYR9a+88QcpzH1YzF9FCGTN0zfCScT6PRmwVC4u9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3DHDWS54u1lLDygUiiIpKOfWPUW08IqCOWiQbeXKABRuMvVa6o1OhUKvzkcJkThe8WYN2wiefLe8hAJCV1oN8PYwzhXZ0BioZIypU/d+mBJrOTi4gtuQOqxEF5x3itSH3KSfKFKgV6vEyBrfsdEzn/sthnbXbrhMyPP4+iIuq594+whPxh6/GQLvPAJ4rE7qNaFMo0yrIKtzPldfcFexrG0OPaR4DduZuEY8sNgctxhiJ2hSFJt8YzpJhiB6Th5I1gn7VcQwpHB0mXEQYc1CRrBzrEQKCAQBrb5HEfZG7vG1L0shQsyHBT9j4T2WY/ooTFCPCZjPOsX/Oi9/5qaDzOm+6mkJESrkzFX1vF2kmXJsTeOmXGH+FXm23rvOBRip+zwCrliAQtoQnNMNfDW39OIur5KKR0HkpoBDcTfUQv8p5+MfaI1MS4OumMdvCAia+oc8kfcVDpiF7hyyBtwkmqyTxn7gqXQOzAKvsMmfKxdWQsvRJzloU2hk0mdudN6N2VWskF2yN75yGUodjcC6UjTNlllKRm+t/VcvwvRN6EMsHGq1SVvVV9iSaD9+Or6o9zw/zjCWIGCo6QdGTJaF7wSGIeyHCdjI1V0eqE6L0yB5q3f1I6ZMw"

        @JvmOverloads
        fun create(gson: Gson? = Gson()): CustomConvertFactory {
            if (gson == null) throw NullPointerException("gson == null")
            return CustomConvertFactory(gson)
        }
    }
}
